package live.zs.jpaboot.service.impl;

import live.zs.jpaboot.dto.PageInfo;
import live.zs.jpaboot.entity.TbOrderEntity;
import live.zs.jpaboot.repo.OrderRepo;
import live.zs.jpaboot.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

/**
 * @author madison
 * @description
 * @date 2021/7/9 01:10
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderRepo orderRepo;

    @Override
    public Page<TbOrderEntity> selectPage(PageInfo pageInfo) {
        PageRequest pageRequest = PageRequest.of(pageInfo.getPageNo(),
                pageInfo.getPageSize(), Sort.by(Sort.Order.desc("createTime")));
        Page<TbOrderEntity> page = orderRepo.findAll(pageRequest);
        return page;
    }

    @Override
    public TbOrderEntity saveOrder(TbOrderEntity orderEntity) {
        return orderRepo.save(orderEntity);
    }
}
